package com.idanchuang.component.redis;

import com.idanchuang.component.redis.aspect.RedisLockAspect;
import com.idanchuang.component.redis.config.DRedisLockConfig;
import com.idanchuang.component.redis.util.pubsub.LockReleasePubSubs;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
 * @author yjy
 * @date 2019/11/27 11:09
 **/
@Configuration
public class ComponentRedisLockAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "spring.redis.lock")
    public DRedisLockConfig dRedisLockConfig() {
        return new DRedisLockConfig();
    }

    @Bean
    @ConditionalOnMissingBean
    public RedisLockAspect redisLockAspect() {
        return new RedisLockAspect();
    }

    @Bean
    @ConditionalOnMissingBean
    public LockReleasePubSubs lockReleasePubSubs(RedisConnectionFactory redisConnectionFactory) {
        return new LockReleasePubSubs(redisConnectionFactory);
    }

}
